package indigo.collections 
{
	/**
	 * A typical Stack implementation. You can add items on top of the Stack and pop them off again.
	 * @author Sebastiaan Holtrop
	 */	
	public class Stack 
	{
		internal var _stack:LinkedList;
		
		/**
		 * Constructor. 
		 */		
		public function Stack():void
		{
			_stack = new LinkedList();
		}
		
		
		/**
		 * Function to detect if the Stack is empty. 
		 * @return Boolean Returns true if the Stack is empty, otherwise returns false.
		 */		
		public function isEmpty():Boolean
		{
			return _stack.isEmpty()
		}
		
		
		/**
		 * Pushes an item on top of the Stack. 
		 * @param item
		 */		
		public function push(item:*):void
		{
			_stack.prepend(item);
		}
		
		
		/**
		 * Removes the first item from the Queue and returns it. 
		 * @return * Returns the first item from the Queue.
		 */		
		public function pop():*
		{
			return _stack.shift();
		}
		
		
		/**
		 * Returns the top item on the Stack without removing it. 
		 * @return * The top item on the Stack. 
		 */		
		public function peek():*
		{
			return _stack.firstLinkedListItem.data;
		}
		
		
		/**
		 * Returns the number of items currently on the Stack. 
		 * @return int
		 */
		public function size():int
		{
			return _stack.size;
		}
		
		
		/**
		 * Returns a string representation of the elements in the Stack.
		 * @return String
		 */
		public function toString():String
		{
			return _stack.toString();
		}
	}
}